package com.easy.common;

import lombok.Data;

import java.io.Serializable;
@Data
public class CommonResult implements Serializable {
    private int code;
    private String message;
    private Object data;
    private int total;

    // 默认构造函数
    public CommonResult() {
    }

    // 构造函数用于自定义 code、message 和 data
    public CommonResult(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 构造函数用于自定义 code、message、data 和 total
    public CommonResult(int code, String message, Object data, int total) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.total = total;
    }

    // 成功响应方法

    // 成功响应，带 data 和 total
    public static CommonResult success(Object data, int total) {
        return new CommonResult(200, "Success", data, total);
    }

    // 成功响应，带 data
    public static CommonResult success(Object data) {
        return new CommonResult(200, "Success", data);
    }

    // 成功响应，无数据
    public static CommonResult success() {
        return new CommonResult(200, "Success", null);
    }

    // 成功响应，带自定义 code 和 message，无数据
    public static CommonResult success(int code, String message) {
        return new CommonResult(code, message, null);
    }

    // 成功响应，带自定义 code 和 message，带数据
    public static CommonResult success(int code, String message, Object data) {
        return new CommonResult(code, message, data);
    }

    // 失败响应方法

    // 失败响应，带 code、message 和 data
    public static CommonResult fail(int code, String message, Object data) {
        return new CommonResult(code, message, data);
    }

    // 失败响应，带 code 和 message
    public static CommonResult fail(int code, String message) {
        return new CommonResult(code, message, null);
    }

    // 失败响应，默认失败信息，无数据
    public static CommonResult fail() {
        return new CommonResult(400, "Operation failed", null);
    }

    // 失败响应，带 message，无数据
    public static CommonResult fail(String message) {
        return new CommonResult(400, message, null);
    }


}
